package com.gpframework.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * 订单枚举
 *
 * @author BrinedFish
 * @create 2022-04-24 10:26
 */
@Getter
public enum OrderEnum {

    VIRTUAL_GOODS("虚拟商品", "1"),
    REAL_GOODS("实物商品", "2"),

    ORDER_TIMEOUT("订单超时（分）", "30"),
    LESHUA_ORDER_TIMEOUT("乐刷订单超时（秒）", "600"),

    /**
     * common_order#order_status
     * 订单状态;（-110 取消订单。-100 超时。100 待支付。110支付中。120 已支付。200 待发货。210待收货。220 已收货。230 已完成。400 退款。）
     */
    CANCEL_ORDER("取消订单", "-110"),
    TIME_OUT("超时", "-100"),
    UNPAY("待支付", "100"),
    PAYMENTS("支付中", "110"),
    PAID("已支付", "120"),
    TO_BE_DELIVERED("待发货", "200"),
    PENDING_RECEIPT("待收货", "210"),
    RECEIVED("已收货", "220"),
    COMPLETED("已完成", "230"),
    REFUND("退款", "400"),


    /**
     * common_order_detail#business_type
     */
    BUY_CARD("购买会员卡"),
    RENEWAL_CARD("续费会员卡"),
    STORED_MONEY_MODIFY("储值"),
    INTEGRAL("积分"),
    DEPOSIT_MODIFY("定金变更"),
    RENT_ARK("租柜"),
    RENEW_RENT_ARK("续柜"),
    BUY_COURSE("购买课程"),
    RENEWAL_COURSE("续费课程"),
    HANDSEL_MODIFY("押金变更"),
    TRANSFER_RENT_ARK("转让租柜"),
    TRANSFER_COURSE("转让课程"),
    BUY_SMS("短信充值"),
    ORDER_REFUND("退款"),
    REPLACEMENT_CARD("补卡"),
    TURN_CARD("转卡"),
    UPGRADE_CARD("升级卡"),
    INSTALLMENT("分期支付"),
    WATER_BAR("购买水吧商品"),
    STOP_CARD("特殊停卡"),
    ENTRY_FEE("入会费"),
    BUY_GROUP_CLASS("买团课"),
    GIVE_AWAY_CARD("赠送卡"),
    GIVE_AWAY_COURSE("赠送课"),
    UPGRADE_COURSE("升级课程"),
//    TRANSFER_GROUP_CLASS("买团课"),

    /**
     * common_order_detail#audit_status
     */
    IN_THE_REVIEW("订单审核中", "1"),
    ORDER_AUDIT_PASS("订单审核通过", "2"),
    PERSONAL_TRAINING("私教"),
    BUY_STORES("购买门店"),
    /**
     * 订单抵扣类型
     */
    COURSE_DEDUCTION("课程抵扣"),
    CARD_DEDUCTION("卡抵扣"),
    PREFERENTIAL("优惠"),

    /**
     * AUDIT_TITLE
     */
    DISCOUNT_AUDIT("折扣审核"),

    /**
     * common_order_detail#refund_status
     */
    NO_REFUND("未退款", "0"),
    IN_APPLICATION("申请中", "10"),
    REFUNDED("已退款", "20"),

    ;

    /**
     * 业务名称 | 注释
     */
    private String name;

    private String key;

    private OrderEnum() {
    }

    private OrderEnum(String name) {
        this.name = name;
    }

    private OrderEnum(String name, String key) {
        this.name = name;
        this.key = key;
    }


    /**
     * 获取已支付状态key（不包含退款）
     *
     * @return
     */
    public static List<String> getPaidStatusKey() {
        // 120 已支付。200 待发货。210待收货。220 已收货。230 已完成。
        return Arrays.asList(PAID.getKey(), TO_BE_DELIVERED.getKey(),
                PENDING_RECEIPT.getKey(), RECEIVED.getKey(), COMPLETED.getKey());
    }

    /**
     * 获取订单业务类型
     *
     * @return
     */
    public static String getOrderBusinessType(String businessType) {
        if (ContractEnum.OPEN_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.BUY_CARD.toString();
        } else if (ContractEnum.CONTINUE_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENEWAL_CARD.toString();
        } else if (ContractEnum.TRANSFER_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.TURN_CARD.toString();
        } else if (ContractEnum.PRIVATE_EDUCATION_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.BUY_COURSE.toString();
        } else if (ContractEnum.RENEWAL_PRIVATE_EDUCATION_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENEWAL_COURSE.toString();
        } else if (ContractEnum.STORED_VALUE_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.STORED_MONEY_MODIFY.toString();
        } else if (ContractEnum.RENT_CABINET_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENT_ARK.toString();
        } else if (ContractEnum.REFUND_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.ORDER_REFUND.toString();
        } else if (ContractEnum.TRANSFER_COURSE_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.TRANSFER_COURSE.toString();
        } else if (ContractEnum.UPGRADE_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.UPGRADE_CARD.toString();
        } else if (ContractEnum.DEPOSIT_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.DEPOSIT_MODIFY.toString();
        } else if (ContractEnum.RENEW_CABINET_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENEW_RENT_ARK.toString();
        } else if (ContractEnum.TRANSFER_CABINET_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.TRANSFER_RENT_ARK.toString();
        }
        return null;
    }

    /**
     * 获取订单业务类型名称
     *
     * @return
     */
    public static String getOrderBusinessName(String businessType) {
        if (ContractEnum.OPEN_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.BUY_CARD.getName();
        } else if (ContractEnum.CONTINUE_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENEWAL_CARD.getName();
        } else if (ContractEnum.TRANSFER_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.TURN_CARD.getName();
        } else if (ContractEnum.PRIVATE_EDUCATION_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.BUY_COURSE.getName();
        } else if (ContractEnum.RENEWAL_PRIVATE_EDUCATION_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENEWAL_COURSE.getName();
        } else if (ContractEnum.STORED_VALUE_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.STORED_MONEY_MODIFY.getName();
        } else if (ContractEnum.RENT_CABINET_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENT_ARK.getName();
        } else if (ContractEnum.REFUND_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.ORDER_REFUND.getName();
        } else if (ContractEnum.TRANSFER_COURSE_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.TRANSFER_COURSE.getName();
        } else if (ContractEnum.UPGRADE_CARD_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.UPGRADE_CARD.getName();
        } else if (ContractEnum.DEPOSIT_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.DEPOSIT_MODIFY.getName();
        } else if (ContractEnum.RENEW_CABINET_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.RENEW_RENT_ARK.getName();
        } else if (ContractEnum.TRANSFER_CABINET_CONTRACT_TEMPLATE.getKey().equals(businessType)) {
            return OrderEnum.TRANSFER_RENT_ARK.getName();
        }
        return null;
    }


    public static String getBusinessName(String businessType) {
        //去除前后空格
        businessType = businessType.trim().trim();
        for (OrderEnum value : OrderEnum.values()) {
            if (value.toString().equals(businessType)) {
                return value.getName();
            }
        }
        return businessType;
    }
}
